﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Register.aspx.cs" Inherits="TimeCapsule.Register" MasterPageFile="~/MasterPage.Master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Head" runat="Server">

<link type="text/css" href="common/blitzer/jquery-ui-1.8.16.custom.css" rel="Stylesheet" />
<script type="text/javascript" src="lib/prototype.js"></script>
<script type="text/javascript" src="lib/jquery-1.7.min.js"></script>
<script type="text/javascript" src="lib/jquery-ui-1.8.16.custom.min.js"></script>

<script type="text/javascript">
	$j = jQuery.noConflict();
	
	var Reging = false;
	var vEmail, vName, vPassword, vPasswordConfirm, vPhone1, vPhone2, vPhone3, vPost1, vPost2, vAddress1, vAddress2;
	var flag_validEmail = false;
	var flag_changeInfo = false;

	$j(function() {
		$j(".btnRegisterSubmit").button();
		
		if ($('hdnValues').value != "")
			ChangeInformation();
	});

	function ChangeInformation() {
		flag_changeInfo = true;
		var arr = $('hdnValues').value.split("~//~");
		
		$('trPswd').hide();
		$('trPswdConfirm').hide();
		
		$('txtEmail').writeAttribute("readonly");
		$('txtEmail').value = arr[0];
		$('txtName').value = arr[1];
		$('txtPhone1').value = arr[2];
		$('txtPhone2').value = arr[3];
		$('txtPhone3').value = arr[4];
		$('txtPost1').value = arr[5];
		$('txtPost2').value = arr[6];
		$('txtAddress1').value = arr[7];
		$('txtAddress2').value = arr[8];
		$('txtPswd')
	}
		
	function validateEmail(tmp) {
		var str = tmp.value;
		var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		if (filter.test(str)) {
			$('lblValidEmail').hide();
			$('lblInvalidEmail').hide();
			$('btnCheckEmail').show();
		}
		else {
			$('lblValidEmail').hide();
			$('lblInvalidEmail').show();
			$('btnCheckEmail').hide();
		}
	}

	function duplicateEmailCheck() {
		new Ajax.Request("lib/CheckValid.ashx", {
			parameters: { id: $('txtEmail').value },
			asynchronous: false,
			evalJS: true,
			on200: function(res) {
				var resValid = res.responseJSON;
				if (resValid.valid == true) {
					flag_validEmail = true;
					alert("사용 가능한 이메일 입니다.");
					$('lblValidEmail').show();
					$('lblInvalidEmail').hide();
					$('btnCheckEmail').hide();
				}
				else {
					flag_validEmail = false;
					$('lblValidEmail').hide();
					$('lblInvalidEmail').show();
					$('btnCheckEmail').hide();
					alert("이미 사용중인 이메일 입니다.");
				}
			},
			on500: function(res) {
				alert("오류가 발생했습니다.");
				document.getElementById("btnCheckEmail").style.display = "none";
				document.getElementById("lblInvalidEmail").style.display = "";
			}
		});
	}

	function validate() {
		if (Reging)
			return false;
		Reging = true;
		if (!flag_changeInfo) {
			if ($('txtEmail').value == "") {
				alert("이메일을 입력하세요.");
				return false;
			}
			if (!flag_validEmail) {
				alert("사용가능한 이메일을 입력하세요.");
				return false;
			}
		}
 		if ( $('txtName').value == "") {
 			alert("이름을 입력하세요.");
 			return false;
 		}
 		if (!flag_changeInfo) {
 			if ($('txtPswd').value == "") {
 				alert("비밀번호를 입력하세요.");
 				return false;
 			}
 			if ($('txtPswd').value.length < 4) {
 				alert("비밀번호는 4자리 이상 입력해주세요.");
 				return false;
 			}
 			if ($('txtPswd').value != $('txtPswdConfirm').value) {
 				alert("비밀번호가 다릅니다.");
 				return false;
 			}
 		}
 		if ($('txtPhone1').value == "" || $('txtPhone2').value == "" || $('txtPhone3').value == "") {
 			alert("올바른 형식의 전화번호를 입력하세요.");
 			return false;
 		}
 		if ($('txtPost1').value == "" || $('txtPost2').value == "") {
 			alert("우편번호를 입력하세요");
 			return false;
 		}
 		if ($('txtAddress1').value == "" || $('txtAddress2').value == "") {
 			alert("주소를 입력하세요");
 			return false;
 		}
		return true;
	}

	function openPostSearchPopup() {
		window.open( "PopPostID.aspx", "PostSearch", "width=410, height=500, top=0, left=200, resizable=no" );
	}
</script>

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="Body" runat="server">
    <div>
		<table id="registerTable" class="Register" cellpadding="0" cellspacing="0">
			<colgroup>
				<col class="property" />
				<col class="value" />
				<col class="title" />
			</colgroup>
			<tr>
				<td colspan="2" class="title">
					<asp:label ID="lblTitle" runat="Server"></asp:label>
				</td>
			</tr>
			<tr>
				<td class="property">
					E-mail
				</td>
				<td class="value">
					<input type="text" id="txtEmail" name="txtEmail" maxlength="128" onkeyup="validateEmail(this)" class="txt_underline_dot" style="width:150px;"/>
					<a href="javascript:duplicateEmailCheck()" id="btnCheckEmail" style="display:none;">중복확인</a>
					<span id="lblInvalidEmail" style="display:none;"><font color="red">사용 불가</font></span>
					<span id="lblValidEmail" style="display:none;"><font color="green">사용 가능</font></span>
				</td>
			</tr>
			<tr>
				<td class="property">
					이름
				</td>
				<td class="value">
					<input type="text" id="txtName" name="txtName" maxlength="16" class="txt_underline_dot" style="width:130px;" />
				</td>
			</tr>
			<tr id="trPswd">
				<td class="property">
					비밀번호
				</td>
				<td class="value">
					<input type="password" id="txtPswd" name="txtPswd" maxlength="16" class="txt_underline_dot" style="width:130px;" />
				</td>
			</tr>
			<tr id="trPswdConfirm">
				<td class="property">
					비밀번호 확인
				</td>
				<td class="value">
					<input type="password" id="txtPswdConfirm" name="txtPswdConfirm" maxlength="16" class="txt_underline_dot" style="width:130px;" />
				</td>
			</tr>
			<tr>
				<td class="property">
					전화번호
				</td>
				<td class="value">
					<input type="text" id="txtPhone1" name="txtPhone1" maxlength="8" class="txt_underline_dot" style="width:30px;" />
					<font color="#C1C1C1">&nbsp;-&nbsp;</font>
					<input type="text" id="txtPhone2" name="txtPhone2" maxlength="4" class="txt_underline_dot" style="width:30px;" />
					<font color="#C1C1C1">&nbsp;-&nbsp;</font>
					<input type="text" id="txtPhone3" name="txtPhone3" maxlength="4" class="txt_underline_dot" style="width:30px;" />
				</td>
			</tr>
			<tr>
				<td class="propertyLast">
					주소
				</td>
				<td class="valueLast">
					<input type="text" id="txtPost1" name="txtPost1" readonly="readonly" class="txt_underline_dot" style="width:30px;" onclick="javascript:openPostSearchPopup();"/>
					<font color="#C1C1C1">&nbsp;-&nbsp;</font>
					<input type="text" id="txtPost2" name="txtPost2" readonly="readonly" class="txt_underline_dot" style="width:30px;" onclick="javascript:openPostSearchPopup();" />
					&nbsp;<a href="javascript:openPostSearchPopup();">검색</a>
					<br />
					<input type="text" id="txtAddress1" name="txtAddress1" class="txt_underline_dot" style="width:100%;" />
					<br />
					<input type="text" id="txtAddress2" name="txtAddress2" class="txt_underline_dot" style="width:100%;" />
				</td>
			</tr>
			<tr>
				<td colspan="2" class="tdBtn">
					<asp:Button id="btnSave" name="btnSave" Text="가입" runat="server" OnClientClick="return validate()" OnClick="btnSave_Clicked" class="btnRegisterSubmit" />
					<asp:Button id="btnModify" name="btnModify" Text="변경" runat="server" OnClientClick="return validate()" OnClick="btnModify_Clicked" class="btnRegisterSubmit" />
				</td>
			</tr>
		</table>
		<input type="hidden" id="submitValue" />
    </div>
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="Dialog" runat="Server">

</asp:Content>